<?php

namespace app\modules\admin\models;

use Yii;

/**
 * This is the model class for table "sys_menu_cate".
 *
 * @property int $id
 * @property string $name 名称
 * @property string $icon 图标icon
 * @property int $is_show 默认是否显示
 * @property int $sort 排序
 * @property int $status 状态[-1:删除,0:禁用,1:启用]
 * @property int $created_at 创建时间
 * @property int $updated_at 更新时间
 */
class SysMenuCate extends \yii\db\ActiveRecord
{
    const STATUS_ENABLE = 1;
    const STATUS_DISABLE = 0;
    const STATUS_DEL = -1;
    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return 'sys_menu_cate';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['name', 'icon', ], 'required'],
            [['is_show', 'sort', 'status', 'created_at', 'updated_at'], 'integer'],
            [['created_at', 'updated_at'], 'required'],
            [['name', 'icon'], 'string', 'max' => 32],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'name' => 'Name',
            'icon' => 'Icon',
            'is_show' => 'Is Show',
            'sort' => 'Sort',
            'status' => 'Status',
            'created_at' => 'Created At',
            'updated_at' => 'Updated At',
        ];
    }

    public static function getList()
    {
        return static::find()
                    ->where(['status' => static::STATUS_ENABLE])
                    ->orderBy('sort asc')
                    ->asArray()
                    ->all();
    }
}